home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Misc / emu / p-interp.lha / p-interp-0.5 / TreeSearch.c < prev    next >
C/C++ Source or Header  |  2001-05-20  |  2KB  |  84 lines

  1. /*
  2.  
  3.   P-Code interpreter (to run the apple pascal system)
  4.   Copyright (C) 2000 Mario Klebsch
  5.  
  6.   This program is free software; you can redistribute it and/or modify
  7.   it under the terms of the GNU General Public License as published by
  8.   the Free Software Foundation; either version 2 of the License, or
  9.   (at your option) any later version.
  10.  
  11.   This program is distributed in the hope that it will be useful,
  12.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.   GNU General Public License for more details.
  15.  
  16.   You should have received a copy of the GNU General Public License
  17.   along with this program; if not, write to the Free Software
  18.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.   $Log: TreeSearch.c,v $
  21.   Revision 1.2  2001/05/20 13:12:02  mario
  22.   CVS-Idents und Logs eingefügt
  23.  
  24.  
  25. */
  26.  
  27. #ident "$Id: TreeSearch.c,v 1.2 2001/05/20 13:12:02 mario Exp $";
  28.  
  29. #include <stdio.h>
  30.  
  31. #include "psystem.h"
  32. #include "Memory.h"
  33. #include "Array.h"
  34.  
  35. #undef DEBUG
  36.  
  37. word csp_TreeSearch(word TokenBuf, word ResultPtr, word NodePtr)
  38. {
  39.   word    Link;
  40.  
  41. #ifdef DEBUG
  42.   int i;
  43.  
  44.   for (i=0; i<8;i++)
  45.     putchar(MemRdByte(TokenBuf, i));
  46.   printf(": ");
  47. #endif
  48.  
  49.   while (1)
  50.     {
  51.       int cmp=ByteCmp(TokenBuf, NodePtr, 8);
  52.       if (cmp<0)
  53.     if ((Link=MemRd(WordIndexed(NodePtr,5))))
  54.       NodePtr=Link;            /* follow RightLink            */
  55.     else
  56.       {
  57. #ifdef DEBUG
  58.         printf("not found, should be on right node\n");
  59. #endif
  60.         MemWr(ResultPtr, NodePtr);
  61.         return(0xffff);
  62.       }
  63.       else if (cmp>0)
  64.     if ((Link=MemRd(WordIndexed(NodePtr,4))))
  65.       NodePtr=Link;            /* follow LeftLink            */
  66.     else
  67.       {
  68. #ifdef DEBUG
  69.         printf("not found, should be on left node\n");
  70. #endif
  71.         MemWr(ResultPtr, NodePtr);
  72.         return(1);
  73.       }
  74.       else
  75.     {
  76. #ifdef DEBUG
  77.       printf("found\n");
  78. #endif
  79.       MemWr(ResultPtr, NodePtr);
  80.       return(0);
  81.     }
  82.     }
  83. }
  84.